package com.hc.javabasestudyproject.feature.functionalInterface;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * @Author: huangcheng
 * @CreateTime: 2023-11-22  13:49
 * @Description:
 * @Version: 1.0
 */
public class PredicateInterface {
    public static void main(String[] args) {
        PredicateInterface lambda = new PredicateInterface();
        List<String> list = Arrays.asList("Hello", "wasu", "Lambda", "www", "ok");
        List<String> strList = lambda.filterStr(list, (s) -> s.length() > 3);

        for (String str : strList) {
            System.out.println(str);
        }
    }
    public List<String> filterStr(List<String> list, Predicate<String> pre){
        List<String> strList = new ArrayList<>();
        for (String str : list) {
            if(pre.test(str)){
                strList.add(str);
            }
        }
        return strList;
    }
}
